import helper from '@/common/helper.js';
console.log(helper.websiteUrl);
// 同时发送异步代码的次数
let ajaxTimes = 0;

export const request = (params) => {

	var openid = wx.getStorageSync("openid") || '';
	let header = {
		...params.header
	};

	let urls;
	if (params.url.indexOf('?')) {
		urls = params.url + '&openid=' + openid
	} else {
		urls = params.url + '?openid=' + openid
	}

	const baseUrl = helper.websiteUrl
	return new Promise((resolve, reject) => {
		wx.request({
			...params,
			header: header,
			url: baseUrl + urls,
			success: (result) => {
				resolve(result.data);
			},
			fail: (err) => {
				reject(err);
			},
			complete: () => {
				ajaxTimes--;
				if (ajaxTimes === 0) {
					//  关闭正在等待的图标
					wx.hideLoading();
				}
			}
		});
	})
}